import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class MemberSignService extends BaseService<any> {
  private readonly logger = new Logger(MemberSignService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getPage
   * 对应 PHP: MemberSignService_api::getPage()
   * 逻辑类型: undefined - undefined
   */
  async getPage(where: any[]) {
    // 基于PHP真实逻辑: getPage
    // PHP原文: $where['member_id'] = $this->member_id;         $where['site_id'] = $this->site_id;         $field = 'sign_id, site_id, member_id, days, day_award, co...
where.member_id = this.member_id;
        where.site_id = this.site_id;
        const field = 'sign_id, site_id, member_id, days, day_award, continue_award, continue_tag, create_time, is_sign';
        const search_model = this.model.where(where).field(field).append(.is_sign_name).order('create_time desc'];
        return this.pageQuery(search_model);
    }

    /**
     * 会员签到详情
     * @param int sign_id
     * @return */
    async getInfo(int sign_id)
    {
        const field = 'sign_id, site_id, member_id, days, day_award, continue_award, continue_tag, create_time, is_sign';
        return this.model.where([['sign_id', '=', sign_id], ['site_id', '=', this.site_id], ['member_id', '=', this.member_id))).field(field).append(.is_sign_name).findOrEmpty().toArray(];
    }

    /**
     * 签到
     * @return */
    async sign()
    {

        const sign_config = this.getSign(];
        if (!sign_config.is_use) throw new BusinessException('SIGN_NOT_USE');
        if (!sign_config.sign_period) || !sign_config.day_award)) throw new BusinessException('SIGN_NOT_SET'];
        const sign_period = sign_config.sign_period;//签到周期
        const today = this.model.where([['site_id', '=', this.site_id], ['member_id', '=', this.member_id))).whereDay('create_time').findOrEmpty().toArray(];
        if (!!today)) throw new BusinessException('SIGNED_TODAY'];
        Db.startTrans(];

        try {
            const yesterday = this.model.where([['site_id', '=', this.site_id], ['member_id', '=', this.member_id))).whereDay('create_time', 'yesterday').findOrEmpty().toArray(];
            if (yesterday) {
                const days = yesterday.days;
                days++;
                if (days > sign_period) { //连签天数大于签到周期，连签天数重置为1
                    const days = 1;
                    data.start_time = time(];
                }
                if (!!sign_config.continue_award)) {
                    const continue_signs = array_column(sign_config.continue_award, 'continue_sign'];
                    //获取连签奖励最大天数
                    const max_continue_sign = max(continue_signs);
                    if (max_continue_sign < sign_period && days > max_continue_sign) { //连签奖励最大天数 小于 签到周期 并且 连签天数 大于 连签奖励最大天数 连签天数重置为1
                        const days = 1;
                    }
                }
            } } } else { //断签，连签天数重置为1
                const days = 1;
                data.start_time = time(];
            }

            const awards = [];        //奖励数组
            const continue_text = ''; //连签提示

            //添加签到记录
            data.site_id = this.site_id;
            data.member_id = this.member_id;
            data.days = days;
            data.day_award = sign_config.day_award;
            data.is_sign = 1;
            data.create_time = time(];
            const res = this.model.create(data);
            if (res) {
                //日签奖励发放
                MemberGiftGrantJob.dispatch([
                    site_id: this.site_id,
                    member_id: this.member_id,
                    gift: sign_config.day_award,
                    param: [
                        from_type: 'day_sign_award',
                        memo: '日签奖励'
                    )
                )];
                awards.day_award = sign_config.day_award;

                //签到成功后判断连签天数是否满足连签奖励发放条件
                if (!!sign_config.continue_award)) {
                    foreach (sign_config.continue_award as key => value) {
                        const continue_sign = intval(value.continue_sign);//连续签到天数要求
                        //如果连签天数满足配置条件，发放连签奖励
                        if (res.days == continue_sign) {
                            const gifts = value;
                            unset(gifts.continue_sign, gifts.continue_tag, gifts.receive_limit, gifts.receive_num);

                            continue_data.continue_award = value;
                            continue_data.continue_tag = value.continue_tag;//连签奖励标识
                            if (value.receive_limit == 2) {//receive_limit (1.不限制 2.每人限领 receive_num 次)
                                //周期开始时间
                                const period_start_time = this.model.where([['site_id', '=', this.site_id], ['member_id', '=', this.member_id], ['days', '=', 1], ['start_time', '>', 0))).order('sign_id desc').field('start_time').limit(1).value('start_time'];
                                //周期结束时间
                                const period_end_time = strtotime("+sign_period day", period_start_time];
                                //查询领取次数
                                const receive_count = this.model
                                    .where([['site_id', '=', this.site_id], ['member_id', '=', this.member_id], ['continue_tag', '=', value.continue_tag)))
                                    .whereBetweenTime('create_time', period_start_time, period_end_time).count('sign_id');
                                if (receive_count < value.receive_num) {
                                    //连签奖励发放
                                    MemberGiftGrantJob.dispatch([
                                        site_id: this.site_id,
                                        member_id: this.member_id,
                                        gift: gifts,
                                        param: [
                                            from_type: 'continue_sign_award',
                                            memo: '连签奖励'
                                        )
                                    )];
                                    awards.continue_award = gifts;
                                    const continue_text = get_lang('CONTINUE_SIGN').res.days.get_lang('DAYS'];
                                    //更新连签发放记录
                                    this.model.where([['sign_id', '=', res.sign_id))).update(continue_data];
                                }
                            } } } else { //不限制
                                //连签奖励发放
                                MemberGiftGrantJob.dispatch([
                                    site_id: this.site_id,
                                    member_id: this.member_id,
                                    gift: gifts,
                                    param: [
                                        from_type: 'continue_sign_award',
                                        memo: '连签奖励'
                                    )
                                )];
                                awards.continue_award = gifts;
                                const continue_text = get_lang('CONTINUE_SIGN').res.days.get_lang('DAYS'];
                                //更新连签发放记录
                                this.model.where([['sign_id', '=', res.sign_id))).update(continue_data;
  }
                    }
                }
            }
            Db.commit(];
            const awards_total = this.getTotalAward(awards];
            result.title = get_lang('SIGN_SUCCESS'];
            result.info = continue_text.get_lang('GET_AWARD');
            result.awards = awards_total;
            if (awards_total) {
                return result;
            } } } else {
                return [
                    title: '',
                    info: '',
                    awards: [],
                ];
            }
  }

  /**
   * getInfo
   * 对应 PHP: MemberSignService_api::getInfo()
   * 逻辑类型: undefined - undefined
   */
  async getInfo(sign_id: number) {
    // 基于PHP真实逻辑: getInfo
    // PHP原文: $field = 'sign_id, site_id, member_id, days, day_award, continue_award, continue_tag, create_time, is_sign';         return $this->model->where([['sig...
const field = 'sign_id, site_id, member_id, days, day_award, continue_award, continue_tag, create_time, is_sign';
        return this.model.where([['sign_id', '=', sign_id], ['site_id', '=', this.site_id], ['member_id', '=', this.member_id))).field(field).append(.is_sign_name).findOrEmpty().toArray(];
    }

    /**
     * 签到
     * @return */
    async sign()
    {

        const sign_config = this.getSign(];
        if (!sign_config.is_use) throw new BusinessException('SIGN_NOT_USE');
        if (!sign_config.sign_period) || !sign_config.day_award)) throw new BusinessException('SIGN_NOT_SET'];
        const sign_period = sign_config.sign_period;//签到周期
        const today = this.model.where([['site_id', '=', this.site_id], ['member_id', '=', this.member_id))).whereDay('create_time').findOrEmpty().toArray(];
        if (!!today)) throw new BusinessException('SIGNED_TODAY'];
        Db.startTrans(];

        try {
            const yesterday = this.model.where([['site_id', '=', this.site_id], ['member_id', '=', this.member_id))).whereDay('create_time', 'yesterday').findOrEmpty().toArray(];
            if (yesterday) {
                const days = yesterday.days;
                days++;
                if (days > sign_period) { //连签天数大于签到周期，连签天数重置为1
                    const days = 1;
                    data.start_time = time(];
                }
                if (!!sign_config.continue_award)) {
                    const continue_signs = array_column(sign_config.continue_award, 'continue_sign'];
                    //获取连签奖励最大天数
                    const max_continue_sign = max(continue_signs);
                    if (max_continue_sign < sign_period && days > max_continue_sign) { //连签奖励最大天数 小于 签到周期 并且 连签天数 大于 连签奖励最大天数 连签天数重置为1
                        const days = 1;
                    }
                }
            } } } else { //断签，连签天数重置为1
                const days = 1;
                data.start_time = time(];
            }

            const awards = [];        //奖励数组
            const continue_text = ''; //连签提示

            //添加签到记录
            data.site_id = this.site_id;
            data.member_id = this.member_id;
            data.days = days;
            data.day_award = sign_config.day_award;
            data.is_sign = 1;
            data.create_time = time(];
            const res = this.model.create(data);
            if (res) {
                //日签奖励发放
                MemberGiftGrantJob.dispatch([
                    site_id: this.site_id,
                    member_id: this.member_id,
                    gift: sign_config.day_award,
                    param: [
                        from_type: 'day_sign_award',
                        memo: '日签奖励'
                    )
                )];
                awards.day_award = sign_config.day_award;

                //签到成功后判断连签天数是否满足连签奖励发放条件
                if (!!sign_config.continue_award)) {
                    foreach (sign_config.continue_award as key => value) {
                        const continue_sign = intval(value.continue_sign);//连续签到天数要求
                        //如果连签天数满足配置条件，发放连签奖励
                        if (res.days == continue_sign) {
                            const gifts = value;
                            unset(gifts.continue_sign, gifts.continue_tag, gifts.receive_limit, gifts.receive_num);

                            continue_data.continue_award = value;
                            continue_data.continue_tag = value.continue_tag;//连签奖励标识
                            if (value.receive_limit == 2) {//receive_limit (1.不限制 2.每人限领 receive_num 次)
                                //周期开始时间
                                const period_start_time = this.model.where([['site_id', '=', this.site_id], ['member_id', '=', this.member_id], ['days', '=', 1], ['start_time', '>', 0))).order('sign_id desc').field('start_time').limit(1).value('start_time'];
                                //周期结束时间
                                const period_end_time = strtotime("+sign_period day", period_start_time];
                                //查询领取次数
                                const receive_count = this.model
                                    .where([['site_id', '=', this.site_id], ['member_id', '=', this.member_id], ['continue_tag', '=', value.continue_tag)))
                                    .whereBetweenTime('create_time', period_start_time, period_end_time).count('sign_id');
                                if (receive_count < value.receive_num) {
                                    //连签奖励发放
                                    MemberGiftGrantJob.dispatch([
                                        site_id: this.site_id,
                                        member_id: this.member_id,
                                        gift: gifts,
                                        param: [
                                            from_type: 'continue_sign_award',
                                            memo: '连签奖励'
                                        )
                                    )];
                                    awards.continue_award = gifts;
                                    const continue_text = get_lang('CONTINUE_SIGN').res.days.get_lang('DAYS'];
                                    //更新连签发放记录
                                    this.model.where([['sign_id', '=', res.sign_id))).update(continue_data];
                                }
                            } } } else { //不限制
                                //连签奖励发放
                                MemberGiftGrantJob.dispatch([
                                    site_id: this.site_id,
                                    member_id: this.member_id,
                                    gift: gifts,
                                    param: [
                                        from_type: 'continue_sign_award',
                                        memo: '连签奖励'
                                    )
                                )];
                                awards.continue_award = gifts;
                                const continue_text = get_lang('CONTINUE_SIGN').res.days.get_lang('DAYS'];
                                //更新连签发放记录
                                this.model.where([['sign_id', '=', res.sign_id))).update(continue_data;
  }
                    }
                }
            }
            Db.commit(];
            const awards_total = this.getTotalAward(awards];
            result.title = get_lang('SIGN_SUCCESS'];
            result.info = continue_text.get_lang('GET_AWARD');
            result.awards = awards_total;
            if (awards_total) {
                return result;
            } } } else {
                return [
                    title: '',
                    info: '',
                    awards: [],
                ];
            }
  }

  /**
   * sign
   * 对应 PHP: MemberSignService_api::sign()
   * 逻辑类型: undefined - undefined
   */
  async sign() {
    // 基于PHP真实逻辑: sign
    // PHP原文: $sign_config = $this->getSign();         if (!$sign_config['is_use']) throw new CommonException('SIGN_NOT_USE');         if (empty($sign_config['sign_...
const sign_config = this.getSign(];
        if (!sign_config.is_use) throw new BusinessException('SIGN_NOT_USE');
        if (!sign_config.sign_period) || !sign_config.day_award)) throw new BusinessException('SIGN_NOT_SET'];
        const sign_period = sign_config.sign_period;//签到周期
        const today = this.model.where([['site_id', '=', this.site_id], ['member_id', '=', this.member_id))).whereDay('create_time').findOrEmpty().toArray(];
        if (!!today)) throw new BusinessException('SIGNED_TODAY'];
        Db.startTrans(];

        try {
            const yesterday = this.model.where([['site_id', '=', this.site_id], ['member_id', '=', this.member_id))).whereDay('create_time', 'yesterday').findOrEmpty().toArray(];
            if (yesterday) {
                const days = yesterday.days;
                days++;
                if (days > sign_period) { //连签天数大于签到周期，连签天数重置为1
                    const days = 1;
                    data.start_time = time(];
                }
                if (!!sign_config.continue_award)) {
                    const continue_signs = array_column(sign_config.continue_award, 'continue_sign'];
                    //获取连签奖励最大天数
                    const max_continue_sign = max(continue_signs);
                    if (max_continue_sign < sign_period && days > max_continue_sign) { //连签奖励最大天数 小于 签到周期 并且 连签天数 大于 连签奖励最大天数 连签天数重置为1
                        const days = 1;
                    }
                }
            } } } else { //断签，连签天数重置为1
                const days = 1;
                data.start_time = time(];
            }

            const awards = [];        //奖励数组
            const continue_text = ''; //连签提示

            //添加签到记录
            data.site_id = this.site_id;
            data.member_id = this.member_id;
            data.days = days;
            data.day_award = sign_config.day_award;
            data.is_sign = 1;
            data.create_time = time(];
            const res = this.model.create(data);
            if (res) {
                //日签奖励发放
                MemberGiftGrantJob.dispatch([
                    site_id: this.site_id,
                    member_id: this.member_id,
                    gift: sign_config.day_award,
                    param: [
                        from_type: 'day_sign_award',
                        memo: '日签奖励'
                    )
                )];
                awards.day_award = sign_config.day_award;

                //签到成功后判断连签天数是否满足连签奖励发放条件
                if (!!sign_config.continue_award)) {
                    foreach (sign_config.continue_award as key => value) {
                        const continue_sign = intval(value.continue_sign);//连续签到天数要求
                        //如果连签天数满足配置条件，发放连签奖励
                        if (res.days == continue_sign) {
                            const gifts = value;
                            unset(gifts.continue_sign, gifts.continue_tag, gifts.receive_limit, gifts.receive_num);

                            continue_data.continue_award = value;
                            continue_data.continue_tag = value.continue_tag;//连签奖励标识
                            if (value.receive_limit == 2) {//receive_limit (1.不限制 2.每人限领 receive_num 次)
                                //周期开始时间
                                const period_start_time = this.model.where([['site_id', '=', this.site_id], ['member_id', '=', this.member_id], ['days', '=', 1], ['start_time', '>', 0))).order('sign_id desc').field('start_time').limit(1).value('start_time'];
                                //周期结束时间
                                const period_end_time = strtotime("+sign_period day", period_start_time];
                                //查询领取次数
                                const receive_count = this.model
                                    .where([['site_id', '=', this.site_id], ['member_id', '=', this.member_id], ['continue_tag', '=', value.continue_tag)))
                                    .whereBetweenTime('create_time', period_start_time, period_end_time).count('sign_id');
                                if (receive_count < value.receive_num) {
                                    //连签奖励发放
                                    MemberGiftGrantJob.dispatch([
                                        site_id: this.site_id,
                                        member_id: this.member_id,
                                        gift: gifts,
                                        param: [
                                            from_type: 'continue_sign_award',
                                            memo: '连签奖励'
                                        )
                                    )];
                                    awards.continue_award = gifts;
                                    const continue_text = get_lang('CONTINUE_SIGN').res.days.get_lang('DAYS'];
                                    //更新连签发放记录
                                    this.model.where([['sign_id', '=', res.sign_id))).update(continue_data];
                                }
                            } } } else { //不限制
                                //连签奖励发放
                                MemberGiftGrantJob.dispatch([
                                    site_id: this.site_id,
                                    member_id: this.member_id,
                                    gift: gifts,
                                    param: [
                                        from_type: 'continue_sign_award',
                                        memo: '连签奖励'
                                    )
                                )];
                                awards.continue_award = gifts;
                                const continue_text = get_lang('CONTINUE_SIGN').res.days.get_lang('DAYS'];
                                //更新连签发放记录
                                this.model.where([['sign_id', '=', res.sign_id))).update(continue_data;
  }
                    }
                }
            }
            Db.commit(];
            const awards_total = this.getTotalAward(awards];
            result.title = get_lang('SIGN_SUCCESS'];
            result.info = continue_text.get_lang('GET_AWARD');
            result.awards = awards_total;
            if (awards_total) {
                return result;
            } } } else {
                return [
                    title: '',
                    info: '',
                    awards: [],
                ];
            }
  }

  /**
   * getSignInfo
   * 对应 PHP: MemberSignService_api::getSignInfo()
   * 逻辑类型: undefined - undefined
   */
  async getSignInfo(year: number, month: number) {
    // 基于PHP真实逻辑: getSignInfo
    // PHP原文: $data = [];         $info = $this->getSign();         if ($info['is_use'] == 1) {//判断签到是否开启             $model_result = $this->model->field('create_ti...
const data = [];
        const info = this.getSign(];
        if (info.is_use == 1) {//判断签到是否开启
            const model_result = this.model.field('create_time').where([['site_id', '=', this.site_id], ['member_id', '=', this.member_id))).whereMonth('create_time', year  + '-' . sprintf("%02d", month)).select(];
            const days = [);
            foreach (model_result as key => value) {
                const day = date('d', strtotime(value.create_time)];
                array_push(days, day);
            }
            data.days = days;
            if (!!info.sign_period) && !!info.continue_award)) {//判断签到周期和连签奖励是否设置
                const sign_period = info.sign_period;//签到周期

                const continue_signs = array_column(info.continue_award, 'continue_sign'];
                //获取连签奖励最大天数
                const max_continue_sign = max(continue_signs];
                //周期开始时间
                const period_start_time = this.model.where([['site_id', '=', this.site_id], ['member_id', '=', this.member_id], ['days', '=', 1], ['start_time', '>', 0))).order('sign_id desc').field('start_time').limit(1).value('start_time');
                if (!!period_start_time)) {
                    //周期结束时间
                    const period_end_time = strtotime("+sign_period day", period_start_time];
                    //获取两个时间戳之间的天数组
                    const days_ = this.getDaysArray(period_start_time, period_end_time);
                    foreach (days_as key => value) {
                        const day = key + 1;
                        foreach (info.continue_award as k => v) {
                            if (v.receive_limit == 1) {//不限制次数奖励添加
                                const period_num = intdiv(sign_period, max_continue_sign);//周期内可循环轮次
                                for (i = 0; i < period_num; i++) {
                                    if (max_continue_sign * i + v.continue_sign == day) {
                                        data.period[key].award = true;
                                    }
                                }
                            } } } else {//限制次数奖励添加
                                for (i = 0; i < v.receive_num; i++) {
                                    if (max_continue_sign * i + v.continue_sign == day) {
                                        data.period[key].award = true;
                                    }
                                }
                            }
                        }
                        data.period[key].day = value;
                    }
                } } } else {
                    data.period = [];
                }
            } } } else {
                data.period = [];
            }
  }

  /**
   * getDayAward
   * 对应 PHP: MemberSignService_api::getDayAward()
   * 逻辑类型: undefined - undefined
   */
  async getDayAward(year: number, month: number, day: number) {
    // 基于PHP真实逻辑: getDayAward
    // PHP原文: $max_continue_sign = 1;//连签奖励最大天数         $continue_sign_day = 0;//连签奖励天数          $time = $year.'-'.sprintf("%02d", $month).'-'.sprintf("%02d", $day)...
const max_continue_sign = 1;//连签奖励最大天数
        const continue_sign_day = 0;//连签奖励天数

        const time = year + '-'.sprintf("%02d", month) + '-'.sprintf("%02d", day];
        const info = this.getSign();
        if (!info.is_use) throw new BusinessException('SIGN_NOT_USE');
        if (!info.sign_period) || !info.day_award)) throw new BusinessException('SIGN_NOT_SET');
        const sign_period = info.sign_period;//签到周期
        if (!!info.continue_award)) {
            const continue_signs = array_column(info.continue_award, 'continue_sign'];
            //获取连签奖励最大天数
            const max_continue_sign = max(continue_signs);
  }

  /**
   * getSignConfig
   * 对应 PHP: MemberSignService_api::getSignConfig()
   * 逻辑类型: undefined - undefined
   */
  async getSignConfig() {
    // 基于PHP真实逻辑: getSignConfig
    // PHP原文: $info = $this->getSign();         $today = $this->model->where([['site_id', '=', $this->site_id], ['member_id', '=', $this->member_id]])->whereDay('cr...
const info = this.getSign(];
        const today = this.model.where([['site_id', '=', this.site_id], ['member_id', '=', this.member_id))).whereDay('create_time').findOrEmpty().toArray(];
        const yesterday = this.model.where([['site_id', '=', this.site_id], ['member_id', '=', this.member_id))).whereDay('create_time', 'yesterday').findOrEmpty().toArray(];
        if (!!info.day_award)) {
            const day_award = this.coreMemberService.getGiftContent(this.site_id, info.day_award,'member_sign');
            info.day_award = day_award;
  }

  /**
   * getSign
   * 对应 PHP: MemberSignService_api::getSign()
   * 逻辑类型: undefined - undefined
   */
  async getSign() {
    // 基于PHP真实逻辑: getSign
    // PHP原文: $info = ( new CoreConfigService() )->getConfig($this->site_id, 'SIGN_CONFIG');         if (empty($info)) {             $info = [];             $info[ ...
const info = ( this.coreConfigService ).getConfig(this.site_id, 'SIGN_CONFIG');
        if (!info)) {
            const info = [];
            info[ 'value' ] = [
                is_use: 0,
                sign_period: '',
                day_award: '',
                continue_award: [],
                rule_explain: ''
            ];
  }

  /**
   * getTotalAward
   * 对应 PHP: MemberSignService_api::getTotalAward()
   * 逻辑类型: undefined - undefined
   */
  async getTotalAward(awards: any) {
    // 基于PHP真实逻辑: getTotalAward
    // PHP原文: $total_point = 0;         $total_balance = 0;         $coupon_id = [];         $coupon_list = [];          $is_use_point_day = false;         $is_use_...
const total_point = 0;
        const total_balance = 0;
        const coupon_id = [];
        const coupon_list = [];

        const is_use_point_day = false;
        const is_use_point_continue = false;

        const is_use_balance_day = false;
        const is_use_balance_continue = false;

        const is_use_coupon_day = false;
        const is_use_coupon_continue = false;

        if (!!awards.day_award.point)) {
            if (awards.day_award.point.is_use == 1) {
                const is_use_point_day = true;
                total_point += intval(awards.day_award.point.num);
            }
  }

  /**
   * getDaysArray
   * 对应 PHP: MemberSignService_api::getDaysArray()
   * 逻辑类型: undefined - undefined
   */
  async getDaysArray(start_timestamp: any, end_timestamp: any) {
    // 基于PHP真实逻辑: getDaysArray
    // PHP原文: $start = new DateTime("@$start_timestamp"); // 使用时间戳创建DateTime对象         $end = new DateTime("@$end_timestamp"); // 同上         $interval = new DateInt...
const start = new DateTime("@start_timestamp"]; // 使用时间戳创建DateTime对象
        const end = new DateTime("@end_timestamp"]; // 同上
        const interval = new DateInterval('P1D']; // 每天的周期
        const period = new DatePeriod(start, interval, end]; // 创建周期范围

        const days_ = [);
        foreach (period as day) {
            days_array[] = day.format('Y-m-d'); // 格式化日期并添加到数组
  }

  /**
   * getArrayMerge
   * 对应 PHP: MemberSignService_api::getArrayMerge()
   * 逻辑类型: undefined - undefined
   */
  async getArrayMerge(desc: any, json_wares: any) {
    // 基于PHP真实逻辑: getArrayMerge
    // PHP原文: if (is_array($desc) && is_array($json_wares)) {             $arrayMerge = array();             foreach ($json_wares as $key=>$value) {                ...
if (is_[desc) && is_[json_wares)) {
            const arrayMerge = [];
            foreach (json_wares as key=>value) {
                if (array_key_exists(key, desc)) {
                    arrayMerge[key] = value + desc[key];
                    unset(desc[key)];
                } } } else {
                    arrayMerge[key] = value;
                }
            }
            return arrayMerge+desc;
  }
}
